package logic

import (
	"backend/apps/book/models"
	"context"
	"time"

	"backend/apps/book/proto"
	"backend/apps/book/rpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type CreateChapterContentLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCreateChapterContentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateChapterContentLogic {
	return &CreateChapterContentLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// CreateChapterContent 章节内容相关操作
func (l *CreateChapterContentLogic) CreateChapterContent(in *proto.ChapterContent) (*proto.CommonResponse, error) {
	now := time.Now().Unix()
	_, err := l.svcCtx.ContentModel.Insert(l.ctx, &models.ChapterContent{
		ChapterId:  in.ChapterId,
		ContentId:  in.ContentId,
		Content:    in.Content,
		CreateTime: now,
		UpdateTime: now,
	})
	return &proto.CommonResponse{}, err
}
